<?php

class WP_Widget_AD extends WP_Widget{	
	function __construct(){
		$widget_ops=array('classname'=>'ad1','description'=>"广告");
		parent::__construct(false, "广告", $widget_ops);
	}
	
	function widget($args,$instance){
		extract($args);
		//$title=apply_filters('widget_title', '热门标签', $instance, $this->id_base);
		$content=!empty($instance['content'])?$instance['content']:'';
		echo $before_widget;
		if($title){
			echo $before_title.$title.$after_title;
		}
		//内容
		self::getHtml("content={$content}");
		echo $after_widget;
	}
	
	/*function update($new_instance,$old_instance){
		$instance = $old_instance;
		$instance['content'] = strip_tags(stripslashes($new_instance['content']));;
		return $instance;
	}*/
	
	function form($instance){
		$instance = wp_parse_args((array)$instance,array('content'=>''));
		$content= $instance['content'];
		?>
		<p><label for="<?php echo $this->get_field_id('content'); ?>">广告代码</label><textarea name="<?php echo $this->get_field_name('content'); ?>" id="<?php echo $this->get_field_id('content'); ?>" cols="20" rows="16" class="widefat"><?php echo $content; ?></textarea></p>
	<?php 
	}
	
	function getHtml($args=''){		
		$default=array('content'=>'');
		$parse_args=wp_parse_args($args,$default);
		extract($parse_args);
		
		print_r($parse_args['content']);
		
		echo $parse_args['content'];
		
		/*$args_post = array(
			'orderby' => post_date,
		    'posts_per_page' =>16,
		    'ignore_sticky_posts'=>1,
			'cat'=>$parse_args['cat']
		);
		$post_query = new WP_Query($args_post);
		if($post_query->have_posts()):
			echo '<div class="bd"><ul class="newslist">';
			while($post_query->have_posts()):
				$post_query->the_post();
				echo '<li>';
                echo '<a class="info" href="'.the_permalink().'">'.get_the_title().'</a>';
                echo '</li>';
			endwhile;
			echo '</ul></div>';
			
		 endif;		
		wp_reset_query();*/
	}
}
?>